package ca.abubakrsagar.breadboardsim;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * An action listener used on a drop down menu to be implemented into the
 * properties panel.
 * 
 * @author Sagar & Abubakr
 * @since June 14, 2012
 */
public class DropDownMenuController implements ActionListener {
	private BreadboardPanel breadboardPanel; // The breadboard panel.
	private PropertiesPanel propertiesPanel; // The properties panel.

	/**
	 * Creates a new DropDownMenuController while associating the local panels
	 * to the specified panels.
	 * 
	 * @param breadboardPanel
	 *            The specified breadboard panel.
	 * @param propertiesPanel
	 *            The specified properties panel.
	 */
	public DropDownMenuController(BreadboardPanel breadboardPanel,
			PropertiesPanel propertiesPanel) {
		this.breadboardPanel = breadboardPanel;
		this.propertiesPanel = propertiesPanel;
	}

	/**
	 * Update the state of the switch based on the selected value in the drop
	 * down menu.
	 */
	@Override
	public void actionPerformed(ActionEvent arg0) {
		if (propertiesPanel.getDropDown().getSelectedIndex() == 1) {
			breadboardPanel.getBreadboard().getSwitch()
					.get(propertiesPanel.getPosition()).setOn(true);
			propertiesPanel.display();
			breadboardPanel.repaint();
		} else {
			breadboardPanel.getBreadboard().getSwitch()
					.get(propertiesPanel.getPosition()).setOn(false);
			propertiesPanel.display();
			breadboardPanel.repaint();
		}

	}
}
